local midao = fk.CreateSkill {

  name = "joy__midao",

  tags = {  },

}



midao:addEffect(fk.AskForRetrial, {
  name = "joy__midao",
  anim_type = "control",
  expand_pile = "joy__zhanglu_mi",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(midao.name) and #player:getPile("joy__zhanglu_mi") > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local card = room:askForCard(player, 1, 1, false, midao.name, true, ".|.|.|joy__zhanglu_mi|.|.", "#joy__midao-choose::" .. target.id, "joy__zhanglu_mi")
    if #card > 0 then
      event:setCostData(self, card[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:retrial(Fk:getCardById(event:getCostData(self)), player, data, midao.name)
    if not player.dead then
      player:drawCards(1,midao.name)
    end
  end,
})

return midao